

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">
<h:head></h:head>
<h:body>
	<h:outputStylesheet library="css" name="ticket.css" />

	<p:panelGrid columns="2" style="width:100%;border:none"
		styleClass="headerGrid">
		<p:column>

			<h3>Hello #{ticketController.getCurrentUsername()}!</h3>

		</p:column>
		<p:column>
			<div align="right">
				<a href="#{request.contextPath}/j_spring_security_logout">Logout</a>
			</div>
		</p:column>
	</p:panelGrid>

	<p:panelGrid id="headNavigation" columns="2" style="width:100%"
		styleClass="headerGrid">

		<p:column>
			<div align="right">
				<p:button value="Mailing" outcome="mailing.jsf"></p:button>
			</div>
		</p:column>

	</p:panelGrid>
	<p:panelGrid id="outerTable" columns="2" style="width:100%">
		<p:column colspan="2">
			<h:form>
				<p:panelGrid id="ticketTable" columns="2" style="width:100%"
					styleClass="headerGrid">
					<h:inputText id="ticketId" value="#{ticketController.ticketId}">
					</h:inputText>
					<h:commandButton value="searchTicketByKey" type="submit"
						onclick="return IsEmptyTicket()"
						action="#{ticketController.getIssueByKey()}" />
					<p:selectOneMenu value="#{ticketController.status}">
						<f:selectItems value="#{ticketController.statuses}" var="status"
							itemValue="#{status.name}" itemLabel="#{status.name}" />
					</p:selectOneMenu>
					<h:commandButton value="searchTicketByStatus" type="submit"
						onclick="return IsEmptyTicket()"
						action="#{ticketController.getIssueByStatus()}" />
					<h3>From:</h3>
					<p:calendar value="#{ticketController.dateFrom}" id="calendarFrom">
						<p:ajax event="dateSelect"
							listener="#{ticketController.handleDateFromSelect}"
							update="calendarTo" />
					</p:calendar>
					<h3>To:</h3>
					<p:calendar value="#{ticketController.dateTo}"
						mindate="#{ticketController.dateFrom}" id="calendarTo">
						<p:ajax event="dateSelect"
							listener="#{ticketController.handleDateToSelect}" />
					</p:calendar>
					<h:commandButton value="searchTodayExpireIssues" type="submit"
						action="#{ticketController.getTodayExpireIssues()}" />
					<h:commandButton value="fillDatabaseAllTickets" type="submit"
						action="#{ticketController.getAllTickets()}" />
					<p:commandButton id="downloadLink"
						value="Download latest ticket report" ajax="false"
						icon="ui-icon-arrowthichk-s">
						<p:fileDownload value="#{ticketController.downloadExcelReport()}"></p:fileDownload>
					</p:commandButton>
				</p:panelGrid>
			</h:form>
		</p:column>
		<p:column>
			<h:form>
				<p:panelGrid id="developerTable" columns="1" style="width:100%"
					styleClass="headerGrid">
					<h3>Developer:</h3>
					<p:panelGrid id="selectMenu" columns="3" style="width:100%"
						styleClass="headerGrid">
							<p:selectOneMenu id="developerEmail"
								value="#{userController.userEmail}" required="true"
								requiredMessage="Please, select developer">
								<f:selectItem itemLabel="Select Developer" itemValue=''
									noSelectionOption="true" />
								<f:selectItems value="#{userController.allUsers}" var="user"
									itemValue="#{user.getEmailAddress()}"
									itemLabel="#{user.getEmailAddress()}" />
							</p:selectOneMenu>
							<div align="right">
								<p:message for="developerEmail" errorClass="error"
									infoClass="info" />
							</div>
					</p:panelGrid>
					<p:selectOneRadio id="options" value="#{userController.status}">
						<f:selectItem itemLabel="Show all tickets" itemValue="All" />
						<f:selectItem itemLabel="Show resolved tickets only"
							itemValue="Resolved" />
						<f:selectItem itemLabel="Show unresolved tickets only"
							itemValue="Open" />
					</p:selectOneRadio>
					<h:commandButton value="Submit" type="submit"
						action="#{userController.getReport()}" />
					<p:commandButton id="downloadLink"
						value="Download latest developer report" ajax="false"
						icon="ui-icon-arrowthichk-s">
						<p:fileDownload value="#{ticketController.downloadExcelReport()}"></p:fileDownload>
					</p:commandButton>
				</p:panelGrid>
			</h:form>
		</p:column>
	</p:panelGrid>
	<h:panelGroup rendered="#{ticketController.showTicketTable eq true}">
		<p:treeTable value="#{ticketController.root}" var="ticket"
			rendered="#{not empty ticketController.ticket}">
			<f:facet name="header">  
            Ticket report
         </f:facet>
			<p:column style="width:32%">
				<f:facet name="header">  
               Name  
            </f:facet>
				<h:outputText value="#{ticket.name}" />
			</p:column>
			<p:column style="width:32%">
				<f:facet name="header">  
               Value  
            </f:facet>
				<h:outputText value="#{ticket.value}" />
			</p:column>
		</p:treeTable>
		<h:outputText rendered="#{empty ticketController.ticket}"
			value="No tickets were found." />
	</h:panelGroup>
	<h:panelGroup rendered="#{ticketController.showTicketTable eq false}">
		<p:treeTable value="#{userController.root}" var="ticket">
			<f:facet name="header">  
            Developer report
         </f:facet>
			<p:column style="width:32%">
				<f:facet name="header">  
               Name  
            </f:facet>
				<h:outputText value="#{ticket.name}" />
			</p:column>
			<p:column style="width:32%">
				<f:facet name="header">  
               Value  
            </f:facet>
				<h:outputText value="#{ticket.value}" />
			</p:column>
		</p:treeTable>
	</h:panelGroup>
	<script type="text/javascript">
		function IsEmptyTicket() {
			if (document.getElementById("j_idt4:ticketId").value == "") {
				return false;
			}
			return true;
		}

		function IsEmptyDeveloper() {
			if (document.getElementById("developerId").value == "") {
				return false;
			}
			return true;
		}
	</script>
</h:body>
</html>

